<script setup lang="ts">
import { getAddressList } from '@/services/address';
import type { addressList } from '@/types/address';
import { onMounted, ref } from 'vue';


const isShow = ref(true)
const list = ref<addressList>()

const getAddressListInfo = async ()=>{
  const res = await getAddressList()
  list.value = res.data
}
onMounted(()=>{
  getAddressListInfo()
})
</script>

<template>
  <div class="patient-page">
    <cp-nav-bar title="收货人信息"></cp-nav-bar>
    <!-- 头部提示 -->
    <div v-if="isShow" class="patient-list">
      <div v-for="item in list" :key="item.id" class="patient-item">
        <div class="info">
          <span class="name">{{item.receiver}}</span>
          <span class="id">{{item.mobile.replace(/^(.{3}).+(.{4})$/,'$1****$2')}}</span>
          <span>{{item.province + item.city +item.county + item.addressDetail}}</span>
        </div>
        <div class="icon"><cp-icon name="user-edit" /></div>
        <div v-if="item.isDefault === 1" class="tag">默认</div>
      </div>
      <!-- <div class="patient-tip">{{`最多可添加 ${6} 人`}}</div> -->
    </div>
    <!-- 当收货地址为空 -->
    <div v-else class="padding-top">
      <van-icon name="failure" size="50" />
      <p>暂无收货地址</p>
    </div>
    <!-- 底部按钮 -->
    <div class="patient-next" >
      <van-button @click="$router.push('/address/addaddress')" type="primary" round block>
        新增收货地址
      </van-button>
    </div>
  </div>
</template>

<style lang="scss">
.padding-top{
  padding-top: 150px;
  // width: 100%;
  // margin: 0 auto;
  text-align: center;
}
.foot{
  width: 100%;
  position: absolute;
  left: 0;
  bottom: 0;
  .van-button{
    width: 90%;
    text-align: center;
    margin: 0 auto;
    margin: 20px;
  }
}

// TODO
.patient-page {
  padding: 46px 0 80px;
  :deep() {
    .van-popup {
      width: 100%;
      height: 100%;
    }
  }
}

.patient-list {
  padding: 15px;
}
.patient-item {
  display: flex;
  align-items: center;
  padding: 15px;
  background-color: var(--cp-bg);
  border-radius: 8px;
  margin-bottom: 15px;
  position: relative;
  border: 1px solid var(--cp-bg);
  transition: all 0.3s;
  overflow: hidden;
  .info {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
    span {
      color: var(--cp-tip);
      margin-right: 20px;
      line-height: 30px;
      &.name {
        font-size: 16px;
        color: var(--cp-text1);
        width: 80px;
        margin-right: 0;
      }
      &.id {
        color: var(--cp-text2);
        width: 180px;
      }
    }
  }
  .icon {
    color: var(--cp-tag);
    width: 20px;
    text-align: center;
  }
  .tag {
    position: absolute;
    right: 60px;
    top: 21px;
    width: 30px;
    height: 16px;
    font-size: 10px;
    color: #fff;
    background-color: var(--cp-primary);
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  &.selected {
    border-color: var(--cp-primary);
    background-color: var(--cp-plain);
    .icon {
      color: var(--cp-primary);
    }
  }
}
.patient-add {
  background-color: var(--cp-bg);
  color: var(--cp-primary);
  text-align: center;
  padding: 15px 0;
  border-radius: 8px;
  .cp-icon {
    font-size: 24px;
  }
}
.patient-tip {
  color: var(--cp-tag);
  padding: 12px 0;
}
.pb4 {
  padding-bottom: 4px;
}
// 底部操作栏
.van-action-bar {
  padding: 0 10px;
  margin-bottom: 10px;
  .van-button {
    color: var(--cp-price);
    background-color: var(--cp-bg);
  }
}
.demo{
  position: absolute;
  left: 0;
  bottom: 70px;
  width: 100%;
  .title{
    text-align: center;
    font-size: 16px;
  }
  .content-id{
    display: flex;
    justify-content: space-between;
    margin: 10px 20px;
    .van-button{
      width: 60px;
      height: 20px;
      font-size: 12px;
      margin-right: 10px;
    }
  }
}
.disabled{
    display: none;
  }

  .patient-change {
  padding: 15px;
  > h3 {
    font-weight: normal;
    margin-bottom: 5px;
  }
  > p {
    color: var(--cp-text3);
  }
}
.patient-next {
  padding: 15px;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 80px;
  box-sizing: border-box;
}
</style>
